import java.util.Iterator;
import java.util.Properties;
import java.util.Set;

import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.naming.InitialContext;

import org.jboss.jmx.adaptor.rmi.RMIAdaptor;

public class JmxMonitorJboss1 {

	public static void main(String[] args) throws Exception {

		// Get RMIAdaptor Object
		Properties pro = new Properties();
		pro.setProperty("java.naming.factory.initial",
				"org.jnp.interfaces.NamingContextFactory");
		pro.setProperty("java.naming.provider.url",
				"jnp://192.168.111.128:1099");
		pro.setProperty("java.naming.factory.url.pkgs",
				"org.jboss.naming:org.jnp.interfaces");
		InitialContext ic = new InitialContext(pro);
		RMIAdaptor server = (RMIAdaptor) ic.lookup("jmx/rmi/RMIAdaptor");

		// Get the MBeanInfo for the JNDIView MBean
		ObjectName name = new ObjectName("jboss:service=JNDIView");
		MBeanInfo info = server.getMBeanInfo(name);
		System.out.println("JNDIView Class: " + info.getClassName());
		MBeanOperationInfo[] opInfo = info.getOperations();
		System.out.println("JNDIView Operations: ");
		for (int o = 0; o < opInfo.length; o++) {
			MBeanOperationInfo op = opInfo[o];
			String returnType = op.getReturnType();
			String opName = op.getName();
			System.out.print(" + " + returnType + " " + opName + "(");
			MBeanParameterInfo[] params = op.getSignature();
			for (int p = 0; p < params.length; p++) {
				MBeanParameterInfo paramInfo = params[p];
				String pname = paramInfo.getName();
				String type = paramInfo.getType();
				if (pname.equals(type))
					System.out.print(type);
				else
					System.out.print(type + " " + name);
				if (p < params.length - 1)
					System.out.print("d");
			}
			System.out.println(")");
		}

		// Get all MBeans
		Set mbSet = server.queryMBeans(null, null); //
		for (Iterator it = mbSet.iterator(); it.hasNext();) {
			ObjectInstance oi = (ObjectInstance) it.next();
			System.out.println(oi.getObjectName());
		}
	}

}
